<?php
/*********************************************
 *  CPG Dragonfly™ CMS
 *********************************************
	Copyright © since 2010 by CPG-Nuke Dev Team
	http://dragonflycms.org

	Dragonfly is released under the terms and conditions
	of the GNU GPL version 2 or any later version
*/

namespace Poodle\Input;

class POST extends GET
{
	public function html() { return self::fixHTML(self::_get(func_get_args())); }

	# HTML5 form fields
	public function date()          { return self::asDate(self::_get(func_get_args())); }
	public function datetime()      { return self::asDateTime(self::_get(func_get_args())); }
	public function datetime_local(){ return self::asDateTime(self::_get(func_get_args()), true); }
	public function email()         { $v = self::_get(func_get_args()); return (true===self::validateEmail($v) ? self::lcEmail($v) : null); }
	public function month()         { return self::asDateFromMonth(self::_get(func_get_args())); }
	public function week()          { return self::asDateFromWeek(self::_get(func_get_args())); }
	public function time()          { return self::asTime(self::_get(func_get_args())); }
	public function color()         { $v = self::_get(func_get_args()); return (preg_match('/^#([0-9A-F]{3}|[0-9A-F]{6}|rgba?\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})(?:\s*,\s*(0(?:\.[0-9]*)?))?\s*\)|hsla?\(\s*([0-2]?[0-9]{1,2}|3[0-5][0-9]|360)\s*,\s*([0-9]{1,2}|100)%\s*,\s*([0-9]{1,2}|100)%(?:\s*,\s*(0(?:\.[0-9]*)?))?\s*\))$/i', $v) ? $v : null); }
	public function number()        { return self::str2float(self::_get(func_get_args())); }
	public function range()         { return self::str2float(self::_get(func_get_args())); }
	public function tel()           { return self::_get(func_get_args()); }
	public function url()           { $v = self::_get(func_get_args()); return (true===self::validateURI($v) ? $v : null); }

	public static function raw_data()
	{
		global $HTTP_RAW_POST_DATA;
		if (empty($HTTP_RAW_POST_DATA)) {
			$HTTP_RAW_POST_DATA = file_get_contents('php://input');
		}
		return $HTTP_RAW_POST_DATA;
	}

	public static function max_size()
	{
		$size = \Poodle\PHP\INI::get('post_max_size', '8M');
		switch (strtoupper(substr($size,-1))) {
			case 'G': $size *= 1024;
			case 'M': $size *= 1024;
			case 'K': $size *= 1024;
		}
		return (int)$size;
	}

}
